import { defineConfig, loadEnv, ConfigEnv } from 'vite'
import react from '@vitejs/plugin-react-swc'
import path from 'path'

const viteConfig = defineConfig((mode: ConfigEnv) => {
  const env = loadEnv(mode.mode, process.cwd())
  return {
    plugins: [react()],
    root: process.cwd(),
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src') // 配置别名
      },
      extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.mjs']
    },
    // base: env.VITE_PUBLIC_PATH,
    server: {
      host: '0.0.0.0',
      port: env.VITE_PORT as unknown as number,
      open: JSON.parse(env.VITE_OPEN),
      hmr: true,
      proxy: {
        '/api': {
          target: env.VITE_API_URL,
          ws: true,
          changeOrigin: true
          // rewrite: (path) => path.replace(/^\/gitee/, ''),
        }
      }
    },
    build: {
      outDir: 'adminBuild'
    }
  }
})

export default viteConfig
